package com.mycompany.dao.hibernate;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.mycompany.dao.BookingDao;
import com.mycompany.model.Booking;

@Repository("bookingDao")
public class BookingDaoHibernate extends GenericDaoHibernate<Booking, Long> implements BookingDao {

	public BookingDaoHibernate() {
        super(Booking.class);
	}

	public BookingDaoHibernate(Class<Booking> persistentClass,
			SessionFactory sessionFactory) {
		super(persistentClass, sessionFactory);
	}

	public Booking saveBooking(Booking booking) {
		getHibernateTemplate().saveOrUpdate(booking);
		getHibernateTemplate().flush();
		
		return booking;
		
	}

	public void deleteBooking(Booking booking) {
		getHibernateTemplate().delete(booking);
		getHibernateTemplate().flush();
		
	}

	public Booking getBooking(Long userId, Long eventId) {
		return getHibernateTemplate().get(Booking.class, new Booking.Id(userId, eventId));
	}

}
